Back to course home
0% completed
Vote For New Content
Meta Hard Problems
Sliding Window Median (hard)
Solution: Sliding Window Median
Alien Dictionary (hard)
Solution: Alien Dictionary
Minimum Window Substring (hard)
Solution: Minimum Window Substring
Best Meeting Point (hard)
Solution: Best Meeting Point
Maximum Sum of 3 Non-Overlapping Subarrays (hard)
Solution: Maximum Sum of 3 Non-Overlapping Subarrays
Making A Large Island (hard)
Solution: Making A Large Island
Basic Calculator (Hard)
Solution: Basic Calculator
Serialize and Deserialize Binary Tree (hard)
Solution: Serialize and Deserialize Binary Tree
Longest Increasing Path in a Matrix (hard)
Solution: Longest Increasing Path in a Matrix
Valid Palindrome III (hard)
Solution: Valid Palindrome III
Basic Calculator II (medium)
Problem Statement
Given a string s, representing the mathematical expression, evaluate the expression and return the integer value.
The integer division should truncate toward zero.
*Note: You are not allowed to use the built-in functions like eval().
Examples
Example 1:
- Input:
"8*5/4+3-2" - Expected Output:
11 - Justification: The calculation proceeds as follows:
8*5 = 40,40/4 = 10,10+3 = 13,13-2 = 11.
Example 2:
- Input:
"10+20/5*3" - Expected Output:
22 - Justification: The order of operations gives
20/5 = 4,4*3 = 12, and10+12 = 22.
Example 3:
- Input:
"50-25+5*3/2*2-10/2" - Expected Output:
34 - Justification: Following the order of operations:
50 - 25 = 25,(15/2) = 7(rounded down),7*2 = 14,25+14 = 39,10/2 = 5, and39 - 5 = 34.
Try it yourself
Try solving this question here:
Java
Saved to Cloud
. . . .
Solution: Buildings With an Ocean View
Solution: Basic Calculator II
Mark as Completed
On this page
Problem Statement
Examples
Try it yourself